# -*- coding: utf-8 -*-

import Util

class DumpVisitor(Util.VisitorUtil):
    def __init__(self, indent=' '*4):
        Util.VisitorUtil.__init__(self, indent)

    def visitModule(self, obj):
        self.echo('%s module %s {' % (obj.access, obj.id))
        self.acceptMembers(obj)
        self.echo('};')

    def visitInterface(self, obj):
        self.echo('%s interface %s {' % (obj.access, obj.id))
        self.acceptMembers(obj)
        self.echo('};')

    def visitStruct(self, obj):
        self.echo('%s struct %s {' % (obj.access, obj.id))
        self.acceptMembers(obj)
        self.echo('};')

    def visitTypedef(self, obj):
        self.echo('%s typedef %s %s;' % (obj.access, obj.type, obj.id))

    def visitEnum(self, obj):
        self.echo('%s enum %s;' % (obj.access, obj.id))

    def visitOperation(self, obj):
        def parameters(params):
            if None == params or len(params) == 0:
                return 'void'
            else:
                return ', '.join([self.getAbsPath(x.type) + ' ' + x.id for x in params])

        self.echo('%s %s %s(%s);' % (obj.access, self.getAbsPath(obj.ret), obj.id, parameters(obj.params)))

    def visitAttribute(self, obj):
        self.echo('%s %s %s;' % (obj.access, self.getAbsPath(obj.type), obj.id))

    def visitConst(self, obj):
        self.echo('%s %s %s = %s;' % (obj.access, self.getAbsPath(obj.type), obj.id, obj.value))
